<template>
  <default-layout>
    <header-back text="主任信箱" slot="header"></header-back>
    <div
      v-infinite-scroll="loadMore"
      infinite-scroll-disabled="disabledScroll"
      infinite-scroll-distance="10"
      infinite-scroll-immediate-check="false"
      slot="main"
      class="scroll-view">
      <div class="list">
        <div @click="detail(val)" class="list-item" v-for="(val, key) in list" :key="key">
          <div class="send">
            <div class="top">
              <span class="desc">编号：{{val.esc010}}</span>
              <span class="desc">{{val.aae036}}</span>
            </div>
            <div class="tit">{{val.esa201}}</div>
            <div class="con">{{val.esa202}}</div>
          </div>
          <div class="back">
            <div class="top">
              <span>状态：
                <span :class="Number(val.esb001) === 1 ? 'pending' : 'response'">{{Number(val.esb001) === 1 ? '未回复' : '已回复'}}</span>
              </span>
              <span v-if="Number(val.esb001) === 2">回复日期：{{val.esb004}}</span>
            </div>
            <div class="con" v-if="Number(val.esb001) === 2">{{val.esb002}}</div>
          </div>
        </div>
      </div>
      <loading-text v-if="loading"></loading-text>
      <finish-text v-if="noMore"></finish-text>
      <empty v-if="empty"></empty>
      <yd-backtop></yd-backtop>
    </div>
    <transition name="router" mode="out-in">
      <router-view class="fixed-router"></router-view>
    </transition>
  </default-layout>
</template>
<script>
  import HeaderBack from '../../../components/header-back/header-back.vue'
  import LoadingText from '../../../components/loading-text/loading-text.vue'
  import FinishText from '../../../components/finish-text/finish-text.vue'
  import DefaultLayout from '../../../layouts/default-layout/default-layout'
  import {infinite} from '../../../common/js/mixin'
  import Empty from '../../../components/empty/empty'
  import {STORAGE_TYPE} from '../../../common/js/config'

  export default {
    components: {
      Empty,
      DefaultLayout,
      FinishText,
      LoadingText,
      HeaderBack},
    computed: { ...infinite },
    data() {
      return {
        /* 以下五个参数为上拉加载页面必需的参数 */
        loading: true,
        page: 1,
        size: 10,
        total: 0,
        list: []
        /* 以上五个参数为上拉加载页面必需的参数 */
      }
    },
    methods: {
      loadMore() {
        if (this.page === 1) this.list = []
        this.$post('/admin/person/sapi/person/center/my/directormail/list', {
          page: this.page,
          pageSize: this.size
        }, loading => {
          this.loading = loading
        }).then(res => {
          res.data.list.forEach(item => {
            item.aae036 = this.$dateFormat(item.aae036).format('YYYY-MM-DD')
            item.esb004 = this.$dateFormat(item.esb004).format('YYYY-MM-DD')
          })
          this.list = this.list.concat(res.data.list)
          this.total = res.data.pager.totalRecord
          this.page++
        })
      },
      detail(val) {
        sessionStorage.setItem(STORAGE_TYPE.suggest, JSON.stringify(Object.assign({title: '主任信箱'}, val)))
        this.$router.push({
          name: 'myLetterDetail'
        })
      }
    },
    created() {
      this.loadMore()
    }
  }
</script>
<style lang="scss" scoped>
  @import "../../../common/style/variable";
  .list-item{
    background: #fff;
    padding: .2rem;
    display: block;
    &:not(:last-child){
      margin: 0 0 .15rem 0;
    }
    .send{
      padding: 0 0 .2rem 0;
      border-bottom: 1px solid #ededed;
      .top{
        display: flex;
        align-items: center;
        justify-content: space-between;
        color: #666;
        padding: 0 0 .1rem 0;
      }
      .tit{
        width: 100%;
        font-size: .32rem;
        color: #000;
        @include ellipsis;
      }
      .con{
        padding: .05rem 0 0 0;
        width: 100%;
        color: #333;
        @include ellipsis;
      }
    }
    .back{
      padding: .2rem 0 0 0;
      .top{
        color: #333;
        display: flex;
        align-items: center;
        justify-content: space-between;
      }
      .con{
        color: #333;
        width: 100%;
        @include ellipsis;
        padding: .1rem 0 0 0;
      }
    }
  }
  .response{
    color: $primary;
  }
  .pending{
    color: $danger;
  }
</style>
